package com.onpositive.realmview.model;

import java.util.Set;

import com.onpositive.semantic.model.api.property.Category;
import com.onpositive.semantic.model.api.property.DefaultPropertyMetadata;
import com.onpositive.semantic.model.core.IKnownsImageObject;
import com.onpositive.semantic.model.realm.IIdentifiableObject;


public class ColumnConfiguration implements IIdentifiableObject,IKnownsImageObject,Comparable<ColumnConfiguration>{

	protected String id;
	protected String name;
	
	
	public Set<Category> getGroup(){
		return metadata.getGroup();
	}
	
	protected int size;
	private DefaultPropertyMetadata metadata;

	public ColumnConfiguration(String id,DefaultPropertyMetadata md) {
		super();
		this.id = id;
		this.metadata=md;
		String name2 = md.getName();
		if (name2!=null){
			this.name=name2;
		}
		else{
		this.name=Character.toUpperCase(id.charAt(0))+id.substring(1);
		}
	}

	public String getId() {
		return id;
	}

	
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ColumnConfiguration other = (ColumnConfiguration) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	public String getName() {
		return name;
	}

	public int getExpectedChars() {
		Object object = metadata.get(DefaultPropertyMetadata.EXPECTED_CHARS);
		if (object!=null){
			return (Integer)object;
		}
		return Math.max(getName().length(), 10);
	}
	
	public boolean isImageInTitle(){
		Object object = metadata.get(DefaultPropertyMetadata.IMAGE_IN_TITLE);
		if (object!=null){
			return (Boolean)object;
		}
		return false;
	}
	
	public String getImageId(){
		Object object = metadata.get(DefaultPropertyMetadata.IMAGE_KEY);
		if (object==null){
			return null;
		}
		return object.toString();
	}
	
	public String toString(){
		return name;
	}

	public String getImageID() {
		return getImageId();
	}

	public int compareTo(ColumnConfiguration o) {
		return this.getName().compareTo(o.getName());
	}
}
